#pragma once

#include <zenoui/Widget.hpp>
#include <zenoui/widgets/LabelWidget.hpp>
#include <zenoui/draws/ButtonRectDraw.hpp>
#include <stack>

namespace zenoui {

struct TextInputWidget : LabelWidget {
protected:
    bool m_pressed = false;
    bool m_editable = true;
    size_t m_cursor_pos = 0;
    size_t m_selection_pos = 0;
    std::pair<std::u32string, size_t> m_undo_text;
    ButtonRectDraw m_button_rect;

    void property(TextProperty *prop) override;
    void handle(MouseClickEvent *event) override;
    void handle(MouseMoveEvent *event) override;
    void handle(MouseReleaseEvent *event) override;
    void handle(CharInputEvent *event) override;
    void handle(KeyPressEvent *event) override;
    void handle(KeyReleaseEvent *event) override;
    using EmptyWidget::handle;
    void paint() override;

    void do_fit_cursor();
    void do_delete_selection(); // nature selection, forward 4!
    std::u32string do_copy_selection(bool is_cut = false);
    void do_insert_text(std::u32string_view text, bool select_inserted = false);
    void do_insert_char(char32_t ch);
    void do_push_undo();
    void do_pop_undo();

public:
    TextInputWidget();
    ~TextInputWidget();
};

}
